package com.weidft.web;

import java.lang.reflect.Field;
import java.util.Map;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.roma.web.ioc.ContextBeanProvider;
import com.weidft.biz.permission.Role;
import com.weidft.biz.permission.UserGrant;
import com.weidft.biz.picture.PictureService;
import com.weidft.web.biz.WDViewTools;

public class WebContextBeanProvider implements ContextBeanProvider {

    private static ApplicationContext context = new ClassPathXmlApplicationContext(
                                                                                   new String[] { "classpath:/META-INF/spring/bean/*.xml" });

    public Object getBean(Field field) {
        return context.getBean(field.getName());
    }

    public Object getBean(String name) {
        return context.getBean(name);
    }

    public static Object getBeanObject(String name) {
        return context.getBean(name);
    }

    @SuppressWarnings("unchecked")
	public static Map getAllUserGrant() {
        return context.getBeansOfType(UserGrant.class);
    }
    
    @SuppressWarnings("unchecked")
	public static Map getAllRole()
    {
    	return context.getBeansOfType(Role.class);
    }
    
    public static WDViewTools getWDViewTools() {
        return (WDViewTools)context.getBean("wdViewTools",WDViewTools.class);
    }
    
    public static PictureService getPictureService() {
        return (PictureService)context.getBean("pictureService",PictureService.class);
    }
}
